import { DataTable } from '../Common/CommonInterface';
const { ccclass, property } = cc._decorator;

@ccclass
export default class DataBaseMgr {
    //作为所有数据管理者的基类

    //数组作为存储数据的容器
    protected _arrData: DataTable[] = [];

    //当前数据的索引
    private _curIndex: number = null;
    get curIndex() {
        return this._curIndex;
    }
    set curIndex(index: number) {
        this._curIndex = index;
    }

    //存储数据
    addData(data: cc.JsonAsset) {
        //将获取的json类型数据强制转换成DataTabel数组类型
        this._arrData = <DataTable[]>data.json;
    }

    //通过id来获取数据,通过泛型规定取得数据必须是什么类型。
    getDataByID<T extends DataTable>(id: number): T {
        for (let data of this._arrData) {
            if (data.id == id) {
                return <T>data;
            }
        }
        return null;
    }

    //通过索引获取数据
    getDataByIndex<T extends DataTable>(index: number): T {
        return <T>this._arrData[index];
    }

    //通过当前索引获取数据
    getDataByCurIndex<T extends DataTable>(): T {
        return <T>this._arrData[this.curIndex];
    }

    //获取所有数据
    getAllData<T extends DataTable>(): T[] {
        return <T[]>this._arrData;
    }

    //获取几个数据，返回数组的长度
    getSize() {
        return this._arrData.length;
    }
}


export class playerDtMgr extends DataBaseMgr {
    arrPlayerIndex: number[] = [0, 3];
    constructor() {
        super();
    }
}
export class keyCodeMgr extends DataBaseMgr {
    constructor() {
        super();
    }
}

export class bubbleDtMgr extends DataBaseMgr {
    constructor() {
        super();
    }

}
export class propDtMgr extends DataBaseMgr {
    constructor() {
        super();
    }
}
export class levelDtMgr extends DataBaseMgr {
    constructor() {
        super();
    }
}